package me.ezjs.system.model.user;

import me.ezjs.framework.bridge.BaseObject;
import me.ezjs.framework.util.TokenUtil;

import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 系统管理员
 *
 * Created by zero-mac on 16/3/10.
 */
@Entity
@Table(name = "Z_SYSTEM_USER")
public class SystemUser extends BaseObject {

    private String username; // 用户名,required
    private String password; // 密码,required
    private String plainPassword; // 明文密码,不存储,transient
    private String aliasName;//昵称
    private String telephone;// 电话
    private int status = 1;

    // token信息.
    private String token;
    private Date tokenTime;// token生成时间.
    private long tokenPeriod = 0;// token有效期.0表示无限长.

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Transient
    public String getPlainPassword() {
        return plainPassword;
    }

    public void setPlainPassword(String plainPassword) {
        this.plainPassword = plainPassword;
    }

    public String getAliasName() {
        return aliasName;
    }

    public void setAliasName(String aliasName) {
        this.aliasName = aliasName;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Date getTokenTime() {
        return tokenTime;
    }

    public void setTokenTime(Date tokenTime) {
        this.tokenTime = tokenTime;
    }

    public long getTokenPeriod() {
        return tokenPeriod;
    }

    public void setTokenPeriod(long tokenPeriod) {
        this.tokenPeriod = tokenPeriod;
    }

    public String updateToken() {
        this.token = TokenUtil.generate(this.username);
        this.tokenTime = new Date();
        this.tokenPeriod = 0;
        return this.token;
    }
}
